﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WikeSoft.WorkFlowEngine.Entities
{
    public class DataModelInitializer : DropCreateDatabaseIfModelChanges<WorkFlowDbContext> // CreateDatabaseIfNotExists<DataModelContext>
    {
        protected override void Seed(WorkFlowDbContext context)
        {
            var categorys = new List<WorkFlowCategory>
            {
                new WorkFlowCategory{ Id = "2ADE9FDE-FFD8-4536-8E81-AA1BC8C7B2BD".ToUpper(), CategoryName = "所有", ParentId = null,SortIndx = 1,PathCode = "AA"},
                new WorkFlowCategory{ Id = "547FEDC8-DFA0-475C-BF64-7EE43ED41E35".ToUpper(), CategoryName = "请假申请",ParentId = "2ADE9FDE-FFD8-4536-8E81-AA1BC8C7B2BD".ToUpper(),SortIndx = 1,PathCode = "AAAA"},
            };
            context.WorkFlowCategories.AddRange(categorys);


            var defs = new List<WorkFlowDef>
            {
                new WorkFlowDef { Id = "96F5B45A-6C94-4058-A76C-879FE6FFC09B",WorkFlowDefKey = "holiday",WorkFlowDefName = "请假申请",CreateDate = DateTime.Now,IsDelete = false,BusinessUrl = "/Holiday/WorkFlowAuditDetailView",AuditUrl = "#",CategoryId = "547FEDC8-DFA0-475C-BF64-7EE43ED41E35"},
            };

            context.WorkFlowDefs.AddRange(defs);

            var versions = new List<WorkFlowVersion>
            {
                new WorkFlowVersion {Id="9E3E214A-EFEF-41F5-B627-01AA83380B0D",WorkFlowDefId = "96F5B45A-6C94-4058-A76C-879FE6FFC09B",VersionNumber = 1,CreateDate = DateTime.Now,WorkFlowDocument = "<?xml version=\"1.0\"?>  <WorkFlowModel xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">    <Id>96F5B45A-6C94-4058-A76C-879FE6FFC09B</Id>    <FlowDefKey>holiday</FlowDefKey>    <FlowDefName>请假</FlowDefName>    <CreateDate xsi:nil=\"true\" />    <Nodes>      <TaskDefinition>        <Id>9DA5CE9E-6A19-4E01-0C62-CC5FF6490009</Id>        <FlowDefId>96F5B45A-6C94-4058-A76C-879FE6FFC09B</FlowDefId>        <NodeDefName>开始</NodeDefName>        <LeftX>26</LeftX>        <TopX>41</TopX>        <Width>46</Width>        <Height>24</Height>        <NodeType>start</NodeType>      </TaskDefinition>      <TaskDefinition>        <Id>D7D88544-6D77-43A2-02A5-C28DDD005C76</Id>        <FlowDefId>96F5B45A-6C94-4058-A76C-879FE6FFC09B</FlowDefId>        <NodeDefName>项目经理审核</NodeDefName>        <LeftX>155</LeftX>        <TopX>38</TopX>        <Width>93</Width>        <Height>30</Height>        <NodeType>task</NodeType>        <RoleNames>项目经理;</RoleNames>        <RoleIds>1230C652-B69B-4407-95FC-EBB7EB964265;</RoleIds>      </TaskDefinition>      <TaskDefinition>        <Id>F02828C1-050C-43A6-0A4E-DE2766EEECBB</Id>        <FlowDefId>96F5B45A-6C94-4058-A76C-879FE6FFC09B</FlowDefId>        <NodeDefName>结束</NodeDefName>        <LeftX>768</LeftX>        <TopX>41</TopX>        <Width>46</Width>        <Height>24</Height>        <NodeType>end</NodeType>      </TaskDefinition>      <TaskDefinition>        <Id>19EB1E03-F487-4433-05B1-6A29546ADCAF</Id>        <FlowDefId>96F5B45A-6C94-4058-A76C-879FE6FFC09B</FlowDefId>        <NodeDefName>部门主管审核</NodeDefName>        <LeftX>339</LeftX>        <TopX>38</TopX>        <Width>93</Width>        <Height>30</Height>        <NodeType>task</NodeType>        <RoleNames>部门主管;</RoleNames>        <RoleIds>61D72D73-ACD4-4EF9-82BA-DD231B7253BC;</RoleIds>      </TaskDefinition>      <TaskDefinition>        <Id>95BC8046-32CE-4F4E-0885-D4E0793B32F5</Id>        <FlowDefId>96F5B45A-6C94-4058-A76C-879FE6FFC09B</FlowDefId>        <NodeDefName>行政备案</NodeDefName>        <LeftX>572</LeftX>        <TopX>38</TopX>        <Width>93</Width>        <Height>30</Height>        <NodeType>task</NodeType>        <RoleNames>行政;</RoleNames>        <RoleIds>4997DC7A-BE5F-4256-AEF6-6CB321C73243;</RoleIds>      </TaskDefinition>      <TaskDefinition>        <Id>C0FAF484-4E7D-4098-0086-E823F38ADF59</Id>        <FlowDefId>96F5B45A-6C94-4058-A76C-879FE6FFC09B</FlowDefId>        <NodeDefName>总经理审核</NodeDefName>        <LeftX>339</LeftX>        <TopX>180</TopX>        <Width>93</Width>        <Height>30</Height>        <NodeType>task</NodeType>        <RoleNames>总经理;</RoleNames>        <RoleIds>89ABE7D7-75A0-47D6-BA01-333839222119;</RoleIds>      </TaskDefinition>    </Nodes>    <NodeLinks>      <TaskLink>        <FlowDefId>96F5B45A-6C94-4058-A76C-879FE6FFC09B</FlowDefId>        <SourceId>9DA5CE9E-6A19-4E01-0C62-CC5FF6490009</SourceId>        <TargetId>D7D88544-6D77-43A2-02A5-C28DDD005C76</TargetId>        <LinkId>con_49</LinkId>        <LinkType>Flowchart</LinkType>        <StartLeft>71</StartLeft>        <StartTop>50</StartTop>        <StartPostion>RightMiddle</StartPostion>        <EndLeft>152</EndLeft>        <EndTop>50</EndTop>        <EndPostion>LeftMiddle</EndPostion>        <Path>M 0.5 0 L 31.5 0 M 30.5 0 L 41 0 M 40 0 L 50.5 0 M 50 0 L 80 0 </Path>        <LinkNameLeft>114</LinkNameLeft>        <LinkNameTop>53</LinkNameTop>      </TaskLink>      <TaskLink>        <FlowDefId>96F5B45A-6C94-4058-A76C-879FE6FFC09B</FlowDefId>        <SourceId>D7D88544-6D77-43A2-02A5-C28DDD005C76</SourceId>        <TargetId>19EB1E03-F487-4433-05B1-6A29546ADCAF</TargetId>        <LinkId>con_51</LinkId>        <LinkType>Flowchart</LinkType>        <StartLeft>247</StartLeft>        <StartTop>50</StartTop>        <StartPostion>RightMiddle</StartPostion>        <EndLeft>336</EndLeft>        <EndTop>50</EndTop>        <EndPostion>LeftMiddle</EndPostion>        <Path>M 0.5 0 L 31.5 0 M 30.5 0 L 45 0 M 44 0 L 58.5 0 M 58 0 L 88 0 </Path>        <LinkNameLeft>294</LinkNameLeft>        <LinkNameTop>53</LinkNameTop>      </TaskLink>      <TaskLink>        <FlowDefId>96F5B45A-6C94-4058-A76C-879FE6FFC09B</FlowDefId>        <SourceId>19EB1E03-F487-4433-05B1-6A29546ADCAF</SourceId>        <TargetId>95BC8046-32CE-4F4E-0885-D4E0793B32F5</TargetId>        <LinkId>con_53</LinkId>        <LinkType>Flowchart</LinkType>        <StartLeft>431</StartLeft>        <StartTop>50</StartTop>        <StartPostion>RightMiddle</StartPostion>        <EndLeft>569</EndLeft>        <EndTop>50</EndTop>        <EndPostion>LeftMiddle</EndPostion>        <Path>M 0.5 0 L 31.5 0 M 30.5 0 L 69.5 0 M 68.5 0 L 107.5 0 M 107 0 L 137 0 </Path>        <LinkName>小于3天</LinkName>        <Condition>1</Condition>        <LinkNameLeft>503</LinkNameLeft>        <LinkNameTop>53</LinkNameTop>      </TaskLink>      <TaskLink>        <FlowDefId>96F5B45A-6C94-4058-A76C-879FE6FFC09B</FlowDefId>        <SourceId>95BC8046-32CE-4F4E-0885-D4E0793B32F5</SourceId>        <TargetId>F02828C1-050C-43A6-0A4E-DE2766EEECBB</TargetId>        <LinkId>con_55</LinkId>        <LinkType>Flowchart</LinkType>        <StartLeft>664</StartLeft>        <StartTop>50</StartTop>        <StartPostion>RightMiddle</StartPostion>        <EndLeft>765</EndLeft>        <EndTop>50</EndTop>        <EndPostion>LeftMiddle</EndPostion>        <Path>M 0.5 0 L 31.5 0 M 30.5 0 L 51 0 M 50 0 L 70.5 0 M 70 0 L 100 0 </Path>        <LinkNameLeft>717</LinkNameLeft>        <LinkNameTop>53</LinkNameTop>      </TaskLink>      <TaskLink>        <FlowDefId>96F5B45A-6C94-4058-A76C-879FE6FFC09B</FlowDefId>        <SourceId>19EB1E03-F487-4433-05B1-6A29546ADCAF</SourceId>        <TargetId>C0FAF484-4E7D-4098-0086-E823F38ADF59</TargetId>        <LinkId>con_57</LinkId>        <LinkType>Flowchart</LinkType>        <StartLeft>384</StartLeft>        <StartTop>65</StartTop>        <StartPostion>BottomCenter</StartPostion>        <EndLeft>384</EndLeft>        <EndTop>177</EndTop>        <EndPostion>TopCenter</EndPostion>        <Path>M 0 0.5 L 0 31.5 M 0 30.5 L 0 56.5 M 0 55.5 L 0 81.5 M 0 81 L 0 111 </Path>        <LinkName>大于等于3天</LinkName>        <Condition>2</Condition>        <LinkNameLeft>386</LinkNameLeft>        <LinkNameTop>124</LinkNameTop>      </TaskLink>      <TaskLink>        <FlowDefId>96F5B45A-6C94-4058-A76C-879FE6FFC09B</FlowDefId>        <SourceId>C0FAF484-4E7D-4098-0086-E823F38ADF59</SourceId>        <TargetId>95BC8046-32CE-4F4E-0885-D4E0793B32F5</TargetId>        <LinkId>con_59</LinkId>        <LinkType>Flowchart</LinkType>        <StartLeft>431</StartLeft>        <StartTop>192</StartTop>        <StartPostion>RightMiddle</StartPostion>        <EndLeft>617</EndLeft>        <EndTop>65</EndTop>        <EndPostion>BottomCenter</EndPostion>        <Path>M 0.5 127 L 31.5 127 M 30.5 127 L 186 127 M 185.5 127.5 L 185.5 30.5 M 185.5 31 L 185.5 1 </Path>        <LinkNameLeft>590</LinkNameLeft>        <LinkNameTop>195</LinkNameTop>      </TaskLink>    </NodeLinks>  </WorkFlowModel>"},
            };
            context.WorkFlowVersions.AddRange(versions);
            context.SaveChanges();//可以分次提交，也可以最后一次性提交给数据库


        }

    }
}
